#!/usr/bin/env python


import os.path
import io
import itertools


class IoIterator(object):

  def __init__(self, src):
    self.src = itertools.chain.from_iterable(src)
  
  def read(self, n = None):
    return ''.join(itertools.islice(self.src, None, n))


def process(output, inputs):
  path  = os.path.abspath(os.path.dirname(__file__))
  files = (io.FileIO('{0}/source/lesp/{1}'.format(path, f), 'rb') for f in inputs)
  with open('{0}/build/{1}'.format(path, output), 'wb') as f:    
    f.write(IoIterator(files).read())


config = {'98307.user.js' : (
  '__init__.js', 
  'abstract.js', 
  'songfacts.js', 
  'songmeanings.js', 
  'application.js', 
  '__main__.js'
)}


if __name__ == '__main__':
  [process(k, v) for k, v in config.items()]

